<template>
  <div>
    <detailTitle
      title="咨询结果"
      tips="本站所有建议均供用户参考，不可替代专业医师诊断，不可替代医师处方。本站不承担由此导致的相关责任。"
    ></detailTitle>
    <div class="detailBase-container">
      <ElRow>
        <ElCol :span="4">
          <detailBaseItem :title="'姓名'">{{ user.child_name }}</detailBaseItem>
          <detailBaseItem :title="'年龄'">{{
            user.age || '1个月'
          }}</detailBaseItem>
          <detailBaseItem :title="'性别'">{{
            user.sex || '无'
          }}</detailBaseItem>
        </ElCol>
        <template v-if="result.type === 1">
          <ElCol :span="10" class="tongue">
            <el-button
              v-if="showDetailButton"
              class="look-change"
              type="primary"
              icon="el-icon-search"
              @click="showList = true"
              >查看症状变化</el-button
            >
            <detailBaseItem class="tongue-name" title="舌苔">{{
              result.tongue || '无'
            }}</detailBaseItem>
            <detailBaseItem title="症状">{{
              result.symptom_str || '无'
            }}</detailBaseItem>
          </ElCol>
          <ElCol :span="10">
            <detailBaseItem title="调理项目">{{
              result.disease_name || '无'
            }}</detailBaseItem>
            <detailBaseItem title="调理方法">{{
              result.cure || '无'
            }}</detailBaseItem>
            <detailBaseItem title="症状备注">{{
              result.symptom_remark || '无'
            }}</detailBaseItem>
          </ElCol>
        </template>
        <template v-else-if="result.type === 2 && result.symptom_str">
          <ElCol :span="10">
            <detailBaseItem title="症状">{{
              result.symptom_str || '无'
            }}</detailBaseItem>
            <detailBaseItem title="结果">{{
              result.face_result || '无'
            }}</detailBaseItem>
          </ElCol>
          <ElCol :span="10">
            <detailBaseItem title="症状备注">{{
              result.symptom_remark || '无'
            }}</detailBaseItem>
          </ElCol>
        </template>
        <template v-else>
          <ElCol :span="10">
            <detailBaseItem title="症状">无</detailBaseItem>
            <detailBaseItem title="结果">{{
              result.face_result || '无'
            }}</detailBaseItem>
          </ElCol>
          <ElCol :span="10">
            <detailBaseItem title="备注信息">{{
              result.symptom_remark || '无'
            }}</detailBaseItem>
          </ElCol>
        </template>
      </ElRow>
    </div>
    <babyDialog :show.sync="showList">
      <div class="dailog-container fuck-container-go" style="background:#fff">
        <div
          v-for="(item, index) in list"
          :key="index"
          class="fuck-column"
          :style="{width: `${140 * list[0].length}px`}"
        >
          <template v-for="(it, i) in item">
            <div
              v-if="i === 1 && it.id"
              :key="i"
              :title="it.name"
              class="item item-record"
              @click="showRecordDialog(it.id)"
            >
              {{ it.name }}
            </div>
            <div
              v-else-if="i === 1 && !it.id"
              :key="i"
              class="item"
              :title="it.name"
            >
              {{ it.name }}
            </div>
            <div v-else :key="i" class="item" :title="it">
              {{ it }}
            </div>
          </template>
        </div>
      </div>
    </babyDialog>
    <babyDialog :show.sync="isShowDialog">
      <div class="dailog-container">
        <solution
          :hand-list="handList"
          :hand-list-simple="handListSimple"
          :say-list="sayList"
          :food-list="foodList"
          :food-book="foodBook"
          :progress="progress"
        ></solution>
      </div>
    </babyDialog>
  </div>
</template>
<script>
import detailBaseItem from './detailBaseItem';
import detailTitle from './detailTitle';
import babyDialog from '@/components/common/babyDialog/babyDialog';
import solution from '@/components/advisory/advisoryDetail/solution';

export default {
  components: {
    detailBaseItem,
    detailTitle,
    babyDialog,
    solution
  },
  props: {
    user: [Object],
    result: [Object]
  },
  data() {
    return {
      typeArr: [],
      showList: false,
      showDetailButton: false,
      isShowDialog: false,
      user1: {},
      result1: {},
      list: [],
      progress: {},
      handList: {},
      handListSimple: {},
      sayList: {},
      foodList: {},
      foodBook: [],
      commodity: {}
    };
  },
  watch: {
    user(v) {
      if (v.u_id) {
        this.getRecordList();
        this.showDetailButton = true;
      }
    }
  },
  methods: {
    getRecordList() {
      this.$http
        .post(this.$url.getChangeRecord, {
          u_id: this.user.u_id
        })
        .then(res => {
          const arr = [
            ['类别', {name: '咨询结果', id: 0}, '舌苔'].concat(
              res.title.map(it => it.phenomenon_name)
            )
          ];
          res.content.forEach(it => {
            arr.push(
              [
                it.from,
                {name: it.symptoms, id: it.record_id},
                it.tongue
              ].concat(it.symptom)
            );
          });
          this.list = arr;
        })
        .catch(this.$catch);
    },
    showRecordDialog(record_id) {
      this.$http
        .post(this.$url.getRecord, {
          u_id: this.user.u_id,
          is_medical: 2,
          record_id
        })
        .then(res => {
          this.user1 = res.user;
          this.result1 = res.result;
          this.progress = res.progress;
          this.handList = res.handList;
          this.handListSimple = res.handListSimple;
          this.sayList = res.sayList;
          this.foodList = res.foodList;
          this.foodBook = res.foodBook;
          this.commodity = res.commodity;
          this.isShowDialog = true;
        })
        .catch(this.$catch);
    }
  }
};
</script>
<style lang="scss" scoped>
.detailBase-container {
  background-color: #fff;
  box-sizing: border-box;
  padding-left: 20px;
  padding-top: 20px;
  padding-bottom: 20px;
  .el-col {
    padding-left: 1.5em;
    padding-right: 0.5em;
    position: relative;
    &:first-child:after {
      display: none;
    }
    &:after {
      content: '';
      position: absolute;
      width: 1px;
      height: 110px;
      top: -10px;
      left: 0;
      background-color: #eee;
    }
  }
}
.tongue {
  position: relative;
  .tongue-name {
    padding-right: 200px;
  }
  .look-change {
    position: absolute;
    top: -7px;
    right: 40px;
    background-color: #4b90ff;
    color: #fff;
    font-size: 16px;
    font-weight: bold;
    border-radius: 25px;
    padding: 7px 12px;
  }
}
.fuck-container-go {
  padding-top: 40px;
  overflow: auto;
  max-height: 500px;
}
.fuck-column {
  font-size: 16px;
  white-space: nowrap;
  .item {
    display: inline-block;
    padding: 20px;
    width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    color: #847a7a;
    &.item-record {
      cursor: pointer;
      &.hover {
        color: #4b90ff;
      }
    }
  }
  &:first-child {
    font-weight: bold;
    .item {
      color: #333;
    }
  }
  &:nth-child(2n + 1) {
    background: #f7f8fd;
  }
}
</style>
<style lang="scss">
.cxk-detail {
  align-items: center;
}
</style>
